Back to course home
0% completed
Vote For New Content
Amazon Hard Problems
Constrained Subsequence Sum (hard)
Solution: Constrained Subsequence Sum
Number of Valid Subarrays (hard)
Solution: Number of Valid Subarrays
Count Vowels Permutation (hard)
Solution: Count Vowels Permutation
Concatenated Words (hard)
Solution: Concatenated Words
Minimum Replacements to Sort the Array (hard)
Solution: Minimum Replacements to Sort the Array
Count All Valid Pickup and Delivery Options (hard)
Solution: Count All Valid Pickup and Delivery Options
Length of the Longest Valid Substring (hard)
Solution: Length of the Longest Valid Substring
Count Array Pairs Divisible by K (hard)
Solution: Count Array Pairs Divisible by K
Word Ladder (hard)
Solution: Word Ladder
Path with Maximum Sum (hard)
Solution: Path with Maximum Sum
Maximum Length of Subarray With Positive Product (medium)
Problem Statement
Given an integer array nums, find the maximum length of a subarray where the product of all its elements is greater than 0.
A subarray is a sequence of consecutive elements from the original array.
Examples
-
Example 1:
- Input:
nums = [1, -2, 3, 4] - Expected Output:
2 - Justification: The longest subarray with a positive product is
[3, 4], with a length of 2.
- Input:
-
Example 2:
- Input:
nums = [-1, -2, -3, -4] - Expected Output:
4 - Justification: The entire array produces a positive product since an even number of negative numbers multiply to a positive product. Hence, the longest length is 4.
- Input:
-
Example 3:
- Input:
nums = [0, -1, 2, -3, 4, -5, 6] - Expected Output:
5 - Justification: The longest subarray with a positive product is
[2, -3, 4, -5, 6], with a length of 5.
- Input:
Try it yourself
Try solving this question here:
Java
. . . .
Solution: Remove Duplicates from Sorted List
Solution: Maximum Length of Subarray With Positive Product
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself